home *** CD-ROM | disk | FTP | other *** search
/ Amiga CD-Sensation: Golden Games / Amiga CD-Sensation - Ausgabe 2 - Golden Games (1996)(GTI - Schatztruhe)(DE)[!].iso / Brain Activity / UChess / Source / dspcom.c < prev    next >
C/C++ Source or Header  |  1994-06-28  |  52KB  |  2,231 lines

  1. #define CLEARHISTBETWEENMOVES // old way to handle hist table
  2. /*
  3.  * dspcom.c - C source for GNU CHESS
  4.  *
  5.  * Copyright (c) 1988,1989,1990 John Stanback
  6.  * Copyright (c) 1992 Free Software Foundation
  7.  *
  8.  * This file is part of GNU CHESS.
  9.  *
  10.  * GNU Chess is free software; you can redistribute it and/or modify
  11.  * it under the terms of the GNU General Public License as published by
  12.  * the Free Software Foundation; either version 2, or (at your option)
  13.  * any later version.
  14.  *
  15.  * GNU Chess is distributed in the hope that it will be useful,
  16.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18.  * GNU General Public License for more details.
  19.  *
  20.  * You should have received a copy of the GNU General Public License
  21.  * along with GNU Chess; see the file COPYING.  If not, write to
  22.  * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  23.  */
  24. #include "gnuchess.h"
  25. void calc_pgm_rating(void);
  26. void DoEasy(void);
  27. void DoIntermediate(void);
  28. void DoAdvanced(void);
  29.  
  30. #define PTRHEIGHT 55
  31. extern UWORD chip myPointer[];
  32.  
  33. #define MYREPLY (1<<InputReply->mp_SigBit)
  34. extern struct MsgPort *InputReply;
  35. extern struct MsgPort *InThreadPort;
  36. extern struct myMsgStruct Global_Message;
  37.  
  38.  
  39. #if defined NULLMOVE || defined DEEPNULL
  40. extern short int __aligned no_null;
  41. extern short int __aligned null;         /* Null-move already made or not */
  42. extern short int __aligned PVari;        /* Is this the PV */
  43. #endif
  44. extern short __aligned Threat[MAXDEPTH];
  45. extern unsigned short int __aligned PrVar[MAXDEPTH];
  46. extern short __aligned PawnStorm;
  47. extern short __aligned start_stage;
  48. extern short __aligned thrashing_tt; /* must we recycle slots at random. TomV */
  49. extern INTSIZE __aligned amigaboard[64],amigacolor[64];
  50. int __aligned GetEntryDone;
  51.  
  52.  
  53. extern int OpEntryRecvd;
  54. extern char __aligned OpEntryStr[64];
  55. extern INTSIZE Mwpawn[64], Mbpawn[64], Mknight[2][64], Mbishop[2][64];
  56. extern char *version, *patchlevel;
  57. char __aligned mvstr[8][8];
  58. char __aligned mvstrhint[8][8];
  59. char __aligned *InPtr;
  60. #define BOOKMENUNUM 0xc2
  61.  
  62. #ifdef CACHE
  63. extern struct etable __far __aligned etab[2][ETABLE];
  64. #endif
  65.  
  66.  
  67. void algbr2 (SHORT f, SHORT t, SHORT flag);
  68. extern unsigned int TTadd;
  69.  
  70. int __aligned SecsPerMove=10;
  71. extern int IllegalMove;
  72. int __aligned func_num=0;
  73. int __aligned thinkahead=0;
  74. int __aligned ThinkInARow=0;
  75. int __aligned ThinkAheadWorked=0;
  76. int __aligned ThinkAheadDepth=0;
  77.  
  78. extern int backsrchaborted;
  79. extern short int ISZERO;
  80. extern short __aligned background;
  81. int __aligned verifyquiet=0;
  82. int __aligned MouseDropped=0;
  83.  
  84. #include <ctype.h>
  85. #include <signal.h>
  86.  
  87. #ifdef AMIGA
  88. #define __USE_SYSBASE
  89. #include <exec/types.h>
  90. #include <exec/exec.h>
  91. #include <proto/exec.h>
  92. #include <proto/dos.h>
  93. #include <proto/graphics.h>
  94. #include <proto/intuition.h>
  95. struct IntuiMessage __aligned globalmessage;
  96. int __aligned globalmessage_valid=0;
  97. extern struct Window __aligned *wG;
  98. extern int procpri;
  99. extern struct Process *myproc;
  100. extern struct MenuItem MenuItem6;
  101. extern struct Menu Menu1;
  102. extern unsigned char __far cookedchar[128];
  103. extern struct Menu __aligned Menu1;
  104. #define MenuList1 Menu1
  105. extern struct MenuItem __aligned MenuItem8ab;
  106. extern int __aligned MenuStripSet;
  107. #endif
  108.  
  109. #define SIGQUIT SIGINT
  110.  
  111. #ifdef MSDOS
  112. #include <dos.h>
  113. #include <conio.h>
  114. #include <stdlib.h>
  115. #include <string.h>
  116. #include <time.h>
  117. #else
  118. #include <dos.h>
  119. #include <stdlib.h>
  120. #include <string.h>
  121. #include <time.h>
  122. /*
  123. #include <sys/param.h>
  124. #include <sys/types.h>
  125. #include <sys/file.h>
  126. #include <sys/ioctl.h>
  127. */
  128. #endif
  129.  
  130.  
  131. /*
  132.  * ataks.h - Header source for GNU CHESS
  133.  *
  134.  * Copyright (c) 1988,1989,1990 John Stanback
  135.  * Copyright (c) 1992 Free Software Foundation
  136.  *
  137.  * This file is part of GNU CHESS.
  138.  *
  139.  * GNU Chess is free software; you can redistribute it and/or modify
  140.  * it under the terms of the GNU General Public License as published by
  141.  * the Free Software Foundation; either version 2, or (at your option)
  142.  * any later version.
  143.  *
  144.  * GNU Chess is distributed in the hope that it will be useful,
  145.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  146.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  147.  * GNU General Public License for more details.
  148.  *
  149.  * You should have received a copy of the GNU General Public License
  150.  * along with GNU Chess; see the file COPYING.  If not, write to
  151.  * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  152.  */
  153. inline int
  154. SqAtakd2 (ARGSZ int sq, ARGSZ int side)
  155.  
  156. /*
  157.  * See if any piece with color 'side' ataks sq.  First check pawns then
  158.  * Queen, Bishop, Rook and King and last Knight.
  159.  */
  160.  
  161. {
  162.   register INTSIZE u;
  163.   register unsigned char *ppos, *pdir;
  164.   INTSIZE xside;
  165.  
  166.   xside = side ^ 1;
  167.   pdir = nextdir[ptype[xside][pawn]][sq];
  168.   u = pdir[sq];            /* follow captures thread */
  169.   if (u != sq)
  170.     {
  171.       if (board[u] == pawn && color[u] == side)
  172.     return (true);
  173.       u = pdir[u];
  174.       if (u != sq && board[u] == pawn && color[u] == side)
  175.     return (true);
  176.     }
  177.   /* king capture */
  178.   if (distance (sq, PieceList[side][0]) == 1)
  179.     return (true);
  180.   /* try a queen bishop capture */
  181.   ppos = nextpos[bishop][sq];
  182.   pdir = nextdir[bishop][sq];
  183.   u = ppos[sq];
  184.   do
  185.     {
  186.       if (color[u] == neutral)
  187.     u = ppos[u];
  188.       else
  189.     {
  190.       if (color[u] == side && (board[u] == queen || board[u] == bishop))
  191.         return (true);
  192.       u = pdir[u];
  193.     }
  194.   } while (u != sq);
  195.   /* try a queen rook capture */
  196.   ppos = nextpos[rook][sq];
  197.   pdir = nextdir[rook][sq];
  198.   u = ppos[sq];
  199.   do
  200.     {
  201.       if (color[u] == neutral)
  202.     u = ppos[u];
  203.       else
  204.     {
  205.       if (color[u] == side && (board[u] == queen || board[u] == rook))
  206.         return (true);
  207.       u = pdir[u];
  208.     }
  209.   } while (u != sq);
  210.   /* try a knight capture */
  211.   pdir = nextdir[knight][sq];
  212.   u = pdir[sq];
  213.   do
  214.     {
  215.       if (color[u] == side && board[u] == knight)
  216.     return (true);
  217.       u = pdir[u];
  218.   } while (u != sq);
  219.   return (false);
  220. }
  221.  
  222.  
  223. #ifndef OLD_ALGBR
  224. void
  225. algbr (SHORT f, SHORT t, SHORT flag)
  226.  
  227.  
  228. /*
  229.  * Generate move strings in different formats.
  230.  */
  231.  
  232. {
  233.   int m3p;
  234.  
  235.   if (f != t)
  236.     {
  237.       /* algebraic notation */
  238.       mvstr[0][0] = cxx[column (f)];
  239.       mvstr[0][1] = rxx[row (f)];
  240.       mvstr[0][2] = cxx[column (t)];
  241.       mvstr[0][3] = rxx[row (t)];
  242.       mvstr[4][0] = mvstr[0][4] = mvstr[3][0] = '\0';
  243.       if (((mvstr[1][0] = pxx[board[f]]) == 'P') || (flag & promote))
  244.     {
  245.       if (mvstr[0][0] == mvstr[0][2])    /* pawn did not eat */
  246.         {
  247.           mvstr[2][0] = mvstr[1][0] = mvstr[0][2];    /* to column */
  248.           mvstr[2][1] = mvstr[1][1] = mvstr[0][3];    /* to row */
  249.           m3p = 2;
  250.         }
  251.       else
  252.         /* pawn ate */
  253.         {
  254.           mvstr[2][0] = mvstr[1][0] = mvstr[0][0];    /* column */
  255.           mvstr[2][1] = mvstr[1][1] = mvstr[0][2];    /* to column */
  256.           mvstr[2][2] = mvstr[0][3];
  257.           m3p = 3;        /* to row */
  258.         }
  259.       if (flag & promote)
  260.         {
  261.           mvstr[0][4] = mvstr[1][2] = mvstr[2][m3p] = qxx[flag & pmask];
  262.           mvstr[0][5] = mvstr[1][3] = mvstr[2][m3p + 1] = mvstr[3][0] = '\0';
  263. #ifdef CHESSTOOL 
  264.           mvstr[3][0] = mvstr[0][0];    /* Allow e7e8 for chesstool */
  265.           mvstr[3][1] = mvstr[0][1];
  266.           mvstr[3][2] = mvstr[0][2];
  267.           mvstr[3][3] = mvstr[0][3];
  268.           mvstr[3][4] = '\0';
  269. #endif
  270.         } else mvstr[2][m3p] = mvstr[1][2] = '\0';
  271.     }
  272.       else
  273.     /* not a pawn */
  274.     {
  275.       mvstr[2][0] = mvstr[1][0];
  276.       mvstr[2][1] = mvstr[0][1];
  277.       mvstr[2][2] = mvstr[1][1] = mvstr[0][2];    /* to column */
  278.       mvstr[2][3] = mvstr[1][2] = mvstr[0][3];    /* to row */
  279.       mvstr[2][4] = mvstr[1][3] = '\0';
  280.       strcpy (mvstr[3], mvstr[2]);
  281.           mvstr[3][1] = mvstr[0][0];
  282.       mvstr[4][0] = mvstr[1][0]; strcpy(&mvstr[4][1],mvstr[0]);
  283.       if (flag & cstlmask)
  284.         {
  285.           if (t > f)
  286.         {
  287.           //strcpy (mvstr[1], mvstr[0]);
  288.           strcpy (mvstr[1], CP[5]);
  289.           strcpy (mvstr[2], CP[7]);
  290.         }
  291.           else
  292.         {
  293.           //strcpy (mvstr[1], mvstr[0]);
  294.           strcpy (mvstr[1], CP[6]);
  295.           strcpy (mvstr[2], CP[8]);
  296.         }
  297.         }
  298.     }
  299.     }
  300.   else
  301.     mvstr[0][0] = mvstr[1][0] = mvstr[2][0] = mvstr[3][0] = mvstr[4][0] = '\0';
  302. }
  303.  
  304. void
  305. algbr2 (SHORT f, SHORT t, SHORT flag)
  306.  
  307.  
  308. /*
  309.  * Generate move strings in different formats.
  310.  */
  311.  
  312. {
  313.   int m3p;
  314.  
  315.   if (f != t)
  316.     {
  317.       /* algebraic notation */
  318.       mvstrhint[0][0] = cxx[column (f)];
  319.       mvstrhint[0][1] = rxx[row (f)];
  320.       mvstrhint[0][2] = cxx[column (t)];
  321.       mvstrhint[0][3] = rxx[row (t)];
  322.       mvstrhint[4][0] = mvstrhint[0][4] = mvstrhint[3][0] = '\0';
  323.       if (((mvstrhint[1][0] = pxx[board[f]]) == 'P') || (flag & promote))
  324.     {
  325.       if (mvstrhint[0][0] == mvstrhint[0][2])    /* pawn did not eat */
  326.         {
  327.           mvstrhint[2][0] = mvstrhint[1][0] = mvstrhint[0][2];    /* to column */
  328.           mvstrhint[2][1] = mvstrhint[1][1] = mvstrhint[0][3];    /* to row */
  329.           m3p = 2;
  330.         }
  331.       else
  332.         /* pawn ate */
  333.         {
  334.           mvstrhint[2][0] = mvstrhint[1][0] = mvstrhint[0][0];    /* column */
  335.           mvstrhint[2][1] = mvstrhint[1][1] = mvstrhint[0][2];    /* to column */
  336.           mvstrhint[2][2] = mvstrhint[0][3];
  337.           m3p = 3;        /* to row */
  338.         }
  339.       if (flag & promote)
  340.         {
  341.           mvstrhint[0][4] = mvstrhint[1][2] = mvstrhint[2][m3p] = qxx[flag & pmask];
  342.           mvstrhint[0][5] = mvstrhint[1][3] = mvstrhint[2][m3p + 1] = mvstrhint[3][0] = '\0';
  343.         } else mvstrhint[2][m3p] = mvstrhint[1][2] = '\0';
  344.     }
  345.       else
  346.     /* not a pawn */
  347.     {
  348.       mvstrhint[2][0] = mvstrhint[1][0];
  349.       mvstrhint[2][1] = mvstrhint[0][1];
  350.       mvstrhint[2][2] = mvstrhint[1][1] = mvstrhint[0][2];    /* to column */
  351.       mvstrhint[2][3] = mvstrhint[1][2] = mvstrhint[0][3];    /* to row */
  352.       mvstrhint[2][4] = mvstrhint[1][3] = '\0';
  353.       strcpy (mvstrhint[3], mvstrhint[2]);
  354.           mvstrhint[3][1] = mvstrhint[0][0];
  355.       mvstrhint[4][0] = mvstrhint[1][0]; strcpy(&mvstrhint[4][1],mvstrhint[0]);
  356.       if (flag & cstlmask)
  357.         {
  358.           if (t > f)
  359.         {
  360.           strcpy (mvstrhint[1], CP[5]);
  361.           strcpy (mvstrhint[2], CP[7]);
  362.         }
  363.           else
  364.         {
  365.           strcpy (mvstrhint[1], CP[6]);
  366.           strcpy (mvstrhint[2], CP[8]);
  367.         }
  368.         }
  369.     }
  370.     }
  371.   else
  372.     mvstrhint[0][0] = mvstrhint[1][0] = mvstrhint[2][0] = mvstrhint[3][0] = mvstrhint[4][0] = '\0';
  373. }
  374.  
  375.  
  376. #endif // not OLD_ALGBR
  377.  
  378. #ifndef OLD_VERIFY
  379.  
  380. int
  381. VerifyMove (char *s, int iop, unsigned short *mv)
  382.  
  383. /*
  384.  * Compare the string 's' to the list of legal moves available for the
  385.  * opponent. If a match is found, make the move on the board.
  386.  */
  387.  
  388. {
  389.   static SHORT pnt, tempb, tempc, tempsf, tempst, cnt;
  390.   static struct leaf xnode;
  391.   struct leaf *node;
  392.   char piece;
  393.   int r,c,l;
  394.   char mystr[80];
  395.  
  396.   *mv = 0;
  397.  
  398.   if ((s[1] >= 'a') && (s[1] <= 'h'))
  399.    {
  400.     if ((s[0] == 'n') || (s[0] == 'p') || (s[0] == 'b') ||
  401.         (s[0] == 'k') || (s[0] == 'r') || (s[0] == 'q'))
  402.      {
  403.       s[0] = toupper(s[0]);
  404.      }
  405.    }
  406.   if (iop == 2)
  407.     {
  408.       UnmakeMove (opponent, &xnode, &tempb, &tempc, &tempsf, &tempst);
  409.       return (false);
  410.     }
  411.   cnt = 0;
  412.   MoveList (opponent, 2);
  413.   pnt = TrPnt[2];
  414.   while (pnt < TrPnt[3])
  415.     {
  416.       node = &Tree[pnt++];
  417.       algbr (node->f, node->t, (SHORT) node->flags);
  418.       if (strcmp (s, mvstr[0]) == 0 || strcmp (s, mvstr[1]) == 0 ||
  419.       strcmp (s, mvstr[2]) == 0 || strcmp (s, mvstr[3]) == 0
  420.         || strcmp (s, mvstr[4]) == 0)
  421.     {
  422.       cnt++;
  423.       xnode = *node;
  424.     }
  425.     }
  426.   if (cnt == 1)
  427.     {
  428.       MakeMove (opponent, &xnode, &tempb, &tempc, &tempsf, &tempst, &INCscore);
  429.       if (SqAtakd2 (PieceList[opponent][0], computer))
  430.     {
  431.       UnmakeMove (opponent, &xnode, &tempb, &tempc, &tempsf, &tempst);
  432. #if defined CHESSTOOL
  433.       printz (CP[78]);
  434. #else
  435. #ifdef NONDSP
  436. #ifndef AMIGA
  437. /* Illegal move in check */
  438.       printz (CP[77]);
  439.       printz ("\n");
  440. #else
  441.           DisplayComputerMove(CP[77]);
  442. #endif
  443. #else // not nondsp
  444. /* Illegal move in check */
  445.           if (!verifyquiet)
  446.        ShowMessage (CP[77]);
  447. #endif
  448. #endif /* CHESSTOOL */
  449.       return (false);
  450.     }
  451.       else
  452.     {
  453.       if (iop == 1)
  454.         return (true);
  455.       UpdateDisplay (xnode.f, xnode.t, 0, (SHORT) xnode.flags);
  456.       if ((board[xnode.t] == pawn)
  457.           || (xnode.flags & capture)
  458.           || (xnode.flags & cstlmask))
  459.         {
  460.           Game50 = GameCnt;
  461.           ZeroRPT ();
  462.         }
  463.       GameList[GameCnt].depth = GameList[GameCnt].score = 0;
  464.       GameList[GameCnt].nodes = 0;
  465.       ElapsedTime (1);
  466.       GameList[GameCnt].time = (SHORT) (et+50)/100;
  467.       if (TCflag)
  468.         {
  469.           TimeControl.clock[opponent] -= (et-TCadd);
  470.           timeopp[oppptr] = et;
  471.           --TimeControl.moves[opponent];
  472.         }
  473.       *mv = (xnode.f << 8) | xnode.t;
  474.       algbr (xnode.f, xnode.t, false);
  475. #ifdef AMIGA
  476.       strcpy(mystr,mvstr[0]);
  477.       r = mystr[3] - '1';
  478.       c = mystr[2] - 'a';
  479.       l = ((flag.reverse) ? locn (7 - r, 7 - c) : locn (r, c));
  480.       if (color[l] == neutral)
  481.        {
  482.         piece = ' ';
  483.        }
  484.       else if (color[l] == white)
  485.         piece = qxx[board[l]]; /* white are lower case pieces */
  486.       else
  487.         piece = pxx[board[l]]; /* black are upper case pieces */
  488.       if (piece != ' ')
  489.        AnimateAmigaMove(mystr,piece);
  490. #endif
  491.       return (true);
  492.     }
  493.     }
  494. #if defined CHESSTOOL
  495.   printz (CP[78]);
  496. #else
  497. #ifdef NONDSP
  498. /* Illegal move */
  499. #ifdef AMIGA
  500.   if (!verifyquiet)
  501.    {
  502.     //sprintf(mystr,CP[75],s);
  503.     strcpy(mystr,"Illegal move (no match):");
  504.     strcat(mystr,s);
  505.     DisplayComputerMove(mystr);
  506.    }
  507. #else
  508.   printz (CP[75], s);
  509. #endif // AMIGA
  510. #else
  511. /* Illegal move */
  512.   if (!verifyquiet)
  513.    ShowMessage (CP[76]);
  514. #endif
  515. #endif /* CHESSTOOL */
  516. #if !defined CHESSTOOL && !defined XBOARD
  517.   if (cnt > 1)
  518.     ShowMessage (CP[32]);
  519. #endif /* CHESSTOOL */
  520.   return (false);
  521. }
  522. #endif // not old verify
  523.  
  524.  
  525.  
  526.  
  527. #ifdef OLD_ALGBR
  528. void
  529. algbr (INTSIZE int f, INTSIZE int t, INTSIZE int flag)
  530.  
  531.  
  532. /*
  533.  * Generate move strings in different formats.
  534.  */
  535.  
  536. {
  537.   int m3p;
  538.  
  539.   if (f != t)
  540.     {
  541.       /* algebraic notation */
  542.       mvstr[0][0] = cxx[column (f)];
  543.       mvstr[0][1] = rxx[row (f)];
  544.       mvstr[0][2] = cxx[column (t)];
  545.       mvstr[0][3] = rxx[row (t)];
  546.       mvstr[0][4] = mvstr[3][0] = '\0';
  547.       if (((mvstr[1][0] = pxx[board[f]]) == 'P') || (flag & promote))
  548.     {
  549.       if (mvstr[0][0] == mvstr[0][2])    /* pawn did not eat */
  550.         {
  551.           mvstr[2][0] = mvstr[1][0] = mvstr[0][2];    /* to column */
  552.           mvstr[2][1] = mvstr[1][1] = mvstr[0][3];    /* to row */
  553.           m3p = 2;
  554.         }
  555.       else
  556.         /* pawn ate */
  557.         {
  558.           mvstr[2][0] = mvstr[1][0] = mvstr[0][0];    /* column */
  559.           mvstr[2][1] = mvstr[1][1] = mvstr[0][2];    /* to column */
  560.           mvstr[2][2] = mvstr[0][3];
  561.           m3p = 3;        /* to row */
  562.         }
  563.       if (flag & promote)
  564.         {
  565.           mvstr[0][4] = mvstr[1][2] = mvstr[2][m3p] = qxx[flag & pmask];
  566.           mvstr[0][5] = mvstr[1][3] = mvstr[2][m3p + 1] = mvstr[3][0] = '\0';
  567. #ifdef CHESSTOOL
  568.           mvstr[3][0] = mvstr[0][0];    /* Allow e7e8 for chesstool */
  569.           mvstr[3][1] = mvstr[0][1];
  570.           mvstr[3][2] = mvstr[0][2];
  571.           mvstr[3][3] = mvstr[0][3];
  572.           mvstr[3][4] = '\0';
  573. #endif
  574.         }
  575.       mvstr[2][m3p] = mvstr[1][2] = '\0';
  576.     }
  577.       else
  578.     /* not a pawn */
  579.     {
  580.       mvstr[2][0] = mvstr[1][0];
  581.       mvstr[2][1] = mvstr[0][1];
  582.       mvstr[2][2] = mvstr[1][1] = mvstr[0][2];    /* to column */
  583.       mvstr[2][3] = mvstr[1][2] = mvstr[0][3];    /* to row */
  584.       mvstr[2][4] = mvstr[1][3] = '\0';
  585.       strcpy (mvstr[3], mvstr[2]);
  586.       mvstr[3][1] = mvstr[0][0];
  587.       if (flag & cstlmask)
  588.         {
  589.           if (t > f)
  590.         {
  591.           strcpy (mvstr[1], CP[5]);
  592.           strcpy (mvstr[2], CP[7]);
  593.         }
  594.           else
  595.         {
  596.           strcpy (mvstr[1], CP[6]);
  597.           strcpy (mvstr[2], CP[8]);
  598.         }
  599.         }
  600.     }
  601.     }
  602.   else
  603.     mvstr[0][0] = mvstr[1][0] = mvstr[2][0] = mvstr[3][0] = '\0';
  604. }
  605. #endif // old_algbr
  606.  
  607. #ifdef OLD_VERIFY
  608. int
  609. VerifyMove (char *s, INTSIZE int iop, INTSIZE unsigned int *mv)
  610.  
  611. /*
  612.  * Compare the string 's' to the list of legal moves available for the
  613.  * opponent. If a match is found, make the move on the board.
  614.  */
  615.  
  616. {
  617.   static INTSIZE pnt, tempb, tempc, tempsf, tempst, cnt;
  618.   int r,c,l;
  619.   char mystr[80];
  620.   char piece;
  621.   static struct leaf xnode;
  622.   struct leaf *node;
  623.  
  624.   if ((s[1] >= 'a') && (s[1] <= 'h'))
  625.    {
  626.     if ((s[0] == 'n') || (s[0] == 'p') || (s[0] == 'b') ||
  627.         (s[0] == 'k') || (s[0] == 'r') || (s[0] == 'q'))
  628.      {
  629.       s[0] = toupper(s[0]);
  630.      }
  631.    }
  632.   *mv = 0;
  633.   if (iop == 2)
  634.     {
  635.       UnmakeMove (opponent, &xnode, &tempb, &tempc, &tempsf, &tempst);
  636.       return (false);
  637.     }
  638.   cnt = 0;
  639.   MoveList (opponent, 2);
  640.   pnt = TrPnt[2];
  641.   while (pnt < TrPnt[3])
  642.     {
  643.       node = &Tree[pnt++];
  644.       algbr (node->f, node->t, (INTSIZE) node->flags);
  645.       if (strcmp (s, mvstr[0]) == 0 || strcmp (s, mvstr[1]) == 0 ||
  646.       strcmp (s, mvstr[2]) == 0 || strcmp (s, mvstr[3]) == 0)
  647.     {
  648.       cnt++;
  649.       xnode = *node;
  650.     }
  651.     }
  652.   if (cnt == 1)
  653.     {
  654.       MakeMove (opponent, &xnode, &tempb, &tempc, &tempsf, &tempst, &INCscore);
  655.       if (SqAtakd2 (PieceList[opponent][0], computer))
  656.     {
  657.       UnmakeMove (opponent, &xnode, &tempb, &tempc, &tempsf, &tempst);
  658. #if defined CHESSTOOL
  659.       printz (CP[15]);
  660. #else
  661. #ifdef NONDSP
  662. /* Illegal move in check */
  663. #ifndef AMIGA
  664.       printz (CP[77]);
  665.       printz ("\n");
  666. #else
  667.           DisplayComputerMove(CP[77]);
  668. #endif
  669. #else
  670. /* Illegal move in check */
  671.           if (!verifyquiet)
  672.         ShowMessage (CP[77]);
  673. #endif
  674. #endif /* CHESSTOOL */
  675.       return (false);
  676.     }
  677.       else
  678.     {
  679.       if (iop == 1)
  680.         return (true);
  681.       UpdateDisplay (xnode.f, xnode.t, 0, (INTSIZE) xnode.flags);
  682.       if ((board[xnode.t] == pawn)
  683.           || (xnode.flags & capture)
  684.           || (xnode.flags & cstlmask))
  685.         {
  686.           Game50 = GameCnt;
  687.           ZeroRPT ();
  688.         }
  689.       GameList[GameCnt].depth = GameList[GameCnt].score = 0;
  690.       GameList[GameCnt].nodes = 0;
  691.       ElapsedTime (1);
  692.       GameList[GameCnt].time = (INTSIZE) et;
  693.       if (TCflag)
  694.         {
  695.           TimeControl.clock[opponent] -= et;
  696.           timeopp[oppptr] = et;
  697.           --TimeControl.moves[opponent];
  698.         }
  699.       *mv = (xnode.f << 8) | xnode.t;
  700.       algbr (xnode.f, xnode.t, false);
  701. #ifdef AMIGA
  702.       strcpy(mystr,mvstr[0]);
  703.       r = mystr[3] - '1';
  704.       c = mystr[2] - 'a';
  705.       l = ((flag.reverse) ? locn (7 - r, 7 - c) : locn (r, c));
  706.       if (color[l] == neutral)
  707.        {
  708.     //DisplayBeep(0L);
  709.         //Delay(25L);
  710.     //DisplayBeep(0L);
  711.         //Delay(25L);
  712.     //DisplayBeep(0L);
  713.         //Delay(25L);
  714.         piece = ' ';
  715.        }
  716.       else if (color[l] == white)
  717.         piece = qxx[board[l]]; /* white are lower case pieces */
  718.       else
  719.         piece = pxx[board[l]]; /* black are upper case pieces */
  720.       if (piece != ' ')
  721.        AnimateAmigaMove(mystr,piece);
  722. #endif
  723.       return (true);
  724.     }
  725.     }
  726. #if defined CHESSTOOL
  727.   printz (CP[78]);
  728. #else
  729. #ifdef NONDSP
  730. /* Illegal move */
  731. #ifdef AMIGA
  732.   //sprintf(mystr,CP[75],s);
  733.   strcpy(mystr,"Illegal move (no match):");
  734.   strcat(mystr,s);
  735.   if (!verifyquiet)
  736.    DisplayComputerMove(mystr);
  737. #else
  738.   printz (CP[75], s);
  739. #endif
  740. #ifdef DEBUG8
  741.   if (1)
  742.     {
  743.       FILE *D;
  744.       int r, c, l;
  745.       extern unsigned INTSIZE int PrVar[];
  746.       D = fopen ("/tmp/DEBUG", "a+");
  747.       pnt = TrPnt[2];
  748.       fprintf (D, "resp = %d\n", ResponseTime);
  749.       fprintf (D, "iop = %d\n", iop);
  750.       fprintf (D, "matches = %d\n", cnt);
  751.       algbr (hint >> 8, hint & 0xff, (INTSIZE) 0);
  752.       fprintf (D, "hint %s\n", mvstr[0]);
  753.       fprintf (D, "inout move is %s\n", s);
  754.       for (r = 1; PrVar[r]; r++)
  755.     {
  756.       algbr (PrVar[r] >> 8, PrVar[r] & 0xff, (INTSIZE) 0);
  757.       fprintf (D, " %s", mvstr[0]);
  758.     }
  759.       fprintf (D, "\n");
  760.       fprintf (D, "legal move are \n");
  761.       while (pnt < TrPnt[3])
  762.     {
  763.       node = &Tree[pnt++];
  764.       algbr (node->f, node->t, (INTSIZE) node->flags);
  765.       fprintf (D, "%s %s %s %s\n", mvstr[0], mvstr[1], mvstr[2], mvstr[3]);
  766.     }
  767.       fprintf (D, "\n current board is\n");
  768.       for (r = 7; r >= 0; r--)
  769.     {
  770.       for (c = 0; c <= 7; c++)
  771.         {
  772.           l = locn (r, c);
  773.           if (color[l] == neutral)
  774.         fprintf (D, " -");
  775.           else if (color[l] == white)
  776.         fprintf (D, " %c", qxx[board[l]]);
  777.           else
  778.         fprintf (D, " %c", pxx[board[l]]);
  779.         }
  780.       fprintf (D, "\n");
  781.     }
  782.       fprintf (D, "\n");
  783.       fclose (D);
  784.       abort ();
  785.     }
  786. #endif
  787. #else
  788. /* Illegal move */
  789.  if (!verifyquiet)
  790.   ShowMessage (CP[76]);
  791. #endif
  792. #endif /* CHESSTOOL */
  793. #if !defined CHESSTOOL && !defined XBOARD
  794.   if (cnt > 1)
  795.     ShowMessage (CP[32]);
  796. #endif /* CHESSTOOL */
  797.   return (false);
  798. }
  799.  
  800. #endif // OLD_VERIFY
  801.  
  802.  
  803.  
  804. int
  805. parser (char *f, int side)
  806. {
  807.   int c1, r1, c2, r2;
  808.  
  809.   if (f[4] == 'o')
  810.     if (side == black)
  811.       return 0x3C3A;
  812.     else
  813.       return 0x0402;
  814.   else if (f[0] == 'o')
  815.     if (side == black)
  816.       return 0x3C3E;
  817.     else
  818.       return 0x0406;
  819.   else
  820.     {
  821.       c1 = f[0] - 'a';
  822.       r1 = f[1] - '1';
  823.       c2 = f[2] - 'a';
  824.       r2 = f[3] - '1';
  825.       return (locn (r1, c1) << 8) | locn (r2, c2);
  826.     }
  827.   /*NOTREACHED*/
  828. }
  829.  
  830. int myfgets(char *buff,int len,BPTR fd)
  831. {
  832.  char tmpch;
  833.  int done=0;
  834.  int numchars=0;
  835.  int retval;
  836.  
  837.  retval = 1;
  838.  do{
  839.     if (Read(fd,&tmpch,1L) != 1L)
  840.      {
  841.       done = 1;
  842.       retval = 0;
  843.      }
  844.     else
  845.      {
  846.       buff[numchars++] = tmpch;
  847.       if (tmpch == '\n')
  848.        {
  849.         done = 1;
  850.        }
  851.       if (numchars >= (len-1))
  852.        {
  853.         done = 1;
  854.         retval = 0;
  855.        }
  856.      }
  857.   } while (!done);
  858.  buff[numchars] = '\0';
  859.  return(retval);
  860. }
  861.  
  862. void
  863. GetGame (void)
  864. {
  865.   int filefmt;
  866.   int side = black; // was side = computer in 2.51
  867.   char checkstr[8];
  868.   BPTR fd;
  869.   int eps;
  870.   char fname[256], *p;
  871.   int c, i, j;
  872.   INTSIZE sq;
  873.  
  874. /* enter file name */
  875.  if (!GetFileName(fname))
  876.   {
  877.    return;
  878.   }
  879.  (void)SetTaskPri((struct Task *)myproc,0);
  880.  if (fname[0] == 0)
  881.   ShowMessage (CP[63]);
  882. #ifndef AMIGA
  883.   scanz ("%s", fname);
  884. #endif
  885. /* chess.000 */
  886.   if (fname[0] == '\0')
  887.     strcpy (fname, CP[137]);
  888.   if ((fd = Open (fname, MODE_OLDFILE)) != NULL)
  889.     {
  890.       NewGame();
  891.       Delay(10L);
  892.       ShowMessage("Loading Game..");
  893.       Delay(20L);
  894.       myfgets (fname, 256, fd);
  895.       for(i=0;i<5;i++)
  896.        checkstr[i] = fname[i];
  897.       checkstr[5] = 0;
  898.       if (stricmp(checkstr,"Black"))
  899.        {
  900.         DisplayBeep(0L);
  901.         Delay(25L);
  902.         DisplayBeep(0L);
  903.         Close(fd);
  904.         return;
  905.        }
  906.       computer = opponent = white;
  907.       InPtr = fname;
  908.       if (strlen(fname) < 34)
  909.        {
  910.         filefmt = 0;
  911.         DisplayError("   Old Save File format");
  912.        }
  913.       else
  914.        filefmt = 1;
  915.       skip ();
  916.       if (*InPtr == 'c')
  917.     computer = black;
  918.       else
  919.     opponent = black;
  920.       skip ();
  921.       skip ();
  922.       skip ();
  923.       Game50 = atoi (InPtr);
  924.       if (filefmt)
  925.        {
  926.         skip();
  927.         skip();
  928.         eps = atoi(InPtr);
  929.        }
  930.       else
  931.        eps = -1;
  932.       myfgets (fname, 256, fd);
  933.       InPtr = &fname[14];
  934.       castld[white] = ((*InPtr == CP[214][0]) ? true : false);
  935.       skip ();
  936.       skip ();
  937.       castld[black] = ((*InPtr == CP[214][0]) ? true : false);
  938.       myfgets (fname, 256, fd);
  939.       InPtr = &fname[11];
  940.       skipb ();
  941.       TCflag = atoi (InPtr);
  942.       skip ();
  943.       InPtr += 14;
  944.       skipb ();
  945.       OperatorTime = atoi (InPtr);
  946.       myfgets (fname, 256, fd);
  947.       InPtr = &fname[11];
  948.       skipb ();
  949.       TimeControl.clock[white] = atoi (InPtr);
  950.       skip ();
  951.       skip ();
  952.       TimeControl.moves[white] = atoi (InPtr);
  953.       myfgets (fname, 256, fd);
  954.       InPtr = &fname[11];
  955.       skipb ();
  956.       TimeControl.clock[black] = atoi (InPtr);
  957.       skip ();
  958.       skip ();
  959.       TimeControl.moves[black] = atoi (InPtr);
  960.       myfgets (fname, 256, fd);
  961.       for (i = 7; i > -1; i--)
  962.     {
  963.       myfgets (fname, 256, fd);
  964.       p = &fname[2];
  965.       InPtr = &fname[11];
  966.       skipb ();
  967.       for (j = 0; j < 8; j++)
  968.         {
  969.           sq = i * 8 + j;
  970.           if (*p == '.')
  971.         {
  972.           board[sq] = no_piece;
  973.           color[sq] = neutral;
  974.         }
  975.           else
  976.         {
  977.           for (c = 0; c < 8; c++)
  978.             {
  979.               if (*p == pxx[c])
  980.             {
  981.               board[sq] = c;
  982.               color[sq] = black;
  983.             }
  984.             }
  985.           for (c = 0; c < 8; c++)
  986.             {
  987.               if (*p == qxx[c])
  988.             {
  989.               board[sq] = c;
  990.               color[sq] = white;
  991.             }
  992.             }
  993.         }
  994.           p++;
  995.           Mvboard[sq] = atoi (InPtr);
  996.           skip ();
  997.         }
  998.     }
  999.       GameCnt = 0;
  1000.       flag.regularstart = false/*true*/;
  1001.       myfgets (fname, 256, fd);
  1002.       myfgets (fname, 256, fd);
  1003.       myfgets (fname, 256, fd);
  1004.       while (myfgets (fname, 256, fd))
  1005.     {
  1006.       struct GameRec *g;
  1007.  
  1008. /*printf("in while loop\n");*/
  1009.       side = side ^ 1;
  1010.       ++GameCnt;
  1011.       InPtr = fname;
  1012.       skipb ();
  1013.       g = &GameList[GameCnt];
  1014.       g->gmove = parser (InPtr, side);
  1015.       skip ();
  1016.       g->score = atoi (InPtr);
  1017.       skip ();
  1018.       g->depth = atoi (InPtr);
  1019.       skip ();
  1020.       g->nodes = atoi (InPtr);
  1021.       skip ();
  1022.       g->time = atoi (InPtr);
  1023.       skip ();
  1024.       g->flags = c = atoi (InPtr);
  1025.       skip ();
  1026.       g->hashkey = strtol (InPtr, (char **) NULL, 16);
  1027.       skip ();
  1028.       g->hashbd = strtol (InPtr, (char **) NULL, 16);
  1029.           if (filefmt)
  1030.        {
  1031.         skip();
  1032.         g->epssq = atoi(InPtr);
  1033.        }
  1034.           else
  1035.            g->epssq = -1;
  1036.       g->piece = no_piece;
  1037.       g->color = neutral;
  1038.       if (c & (capture | cstlmask))
  1039.         {
  1040.           if (c & capture)
  1041.         {
  1042.           skip ();
  1043.           for (c = 0; c < 8; c++)
  1044.             if (pxx[c] == *InPtr)
  1045.               break;
  1046.           g->piece = c;
  1047.         }
  1048.           skip ();
  1049.           g->color = ((*InPtr == CP[119][0]) ? black : white);
  1050.         }
  1051.     }
  1052.       /* GameCnt--; */
  1053.       //if (TimeControl.clock[white] > 0)
  1054.       //TCflag = true;
  1055.       Close (fd);
  1056. //      TrPnt[1] = 0;
  1057. //      root = &Tree[0];
  1058. //      MoveList (side, 1);
  1059.     }
  1060.   ISZERO = 1;
  1061.   ZeroRPT ();
  1062.   epsquare = eps;
  1063.   InitializeStats ();
  1064.   UpdateDisplay (0, 0, 1, 0);
  1065.   Sdepth = 0;
  1066.   hint = 0;
  1067. //  DisableMoveNow();
  1068. //  if (!TCflag)
  1069. //   {
  1070.     EnableMoveNow();
  1071. //   }
  1072. //  else
  1073. //   {
  1074. //    i = player;
  1075. //    player = black;
  1076. //    UpdateClocks();
  1077. //    player = white;
  1078.  //   UpdateClocks();
  1079.  //   player = i;
  1080.   //  if ((((TimeControl.clock[black])/TimeControl.moves[black]) > 5900) ||
  1081.   //      (((TimeControl.clock[white])/TimeControl.moves[white]) > 5900))
  1082.  //    {
  1083.  //     EnableMoveNow();
  1084.  //    }
  1085.  //  }
  1086.   flag.regularstart = false;
  1087.   Book = 0;
  1088.   if (MenuStripSet)
  1089.    {
  1090.     
  1091.     MenuItem8ab.Flags &= (0xffff ^ CHECKED);
  1092.     SetMenuStrip(wG,&MenuList1);    /* attach any Menu */
  1093.    }
  1094.   ZeroTTable(0);
  1095.   MoveMem128(board,amigaboard);
  1096.   MoveMem128(color,amigacolor);
  1097. #ifndef AMIGA
  1098.    memset ((signed char *) etab, 0, sizeof (etab));
  1099. #else
  1100.    ClearMem(etab,sizeof(etab));
  1101. #endif
  1102.   ShowMessage("Game Loaded");
  1103. #ifdef AMIGA
  1104.   DrawAmigaBoard();
  1105. #endif
  1106.   (void)SetTaskPri((struct Task *)myproc,procpri);
  1107. }
  1108.  
  1109. void
  1110. GetXGame (void)
  1111. {
  1112.   BPTR fd;
  1113.   char fname[256], *p;
  1114.   int c, i, j;
  1115.   INTSIZE sq;
  1116. /* Enter file name */
  1117.   ShowMessage (CP[63]);
  1118. #ifndef AMIGA
  1119.   scanz ("%s", fname);
  1120. #endif
  1121.   if (fname[0] == '\0')
  1122. /* xboard.position.read*/
  1123.     strcpy (fname, CP[205]);
  1124.   if ((fd = Open (fname, MODE_OLDFILE)) != NULL)
  1125.     {
  1126.       NewGame ();
  1127.       flag.regularstart = false;
  1128.       Book = false;
  1129.       myfgets (fname, 256, fd);
  1130.       fname[6] = '\0';
  1131.       if (strcmp (fname, CP[206]))
  1132.     return;
  1133.       myfgets (fname, 256, fd);
  1134.       myfgets (fname, 256, fd);
  1135.       for (i = 7; i > -1; i--)
  1136.     {
  1137.       myfgets (fname, 256, fd);
  1138.       p = fname;
  1139.       for (j = 0; j < 8; j++)
  1140.         {
  1141.           sq = i * 8 + j;
  1142.           if (*p == '.')
  1143.         {
  1144.           board[sq] = no_piece;
  1145.           color[sq] = neutral;
  1146.         }
  1147.           else
  1148.         {
  1149.           for (c = 0; c < 8; c++)
  1150.             {
  1151.               if (*p == qxx[c])
  1152.             {
  1153.               board[sq] = c;
  1154.               color[sq] = black;
  1155.             }
  1156.             }
  1157.           for (c = 0; c < 8; c++)
  1158.             {
  1159.               if (*p == pxx[c])
  1160.             {
  1161.               board[sq] = c;
  1162.               color[sq] = white;
  1163.             }
  1164.             }
  1165.         }
  1166.           p += 2;
  1167.         }
  1168.     }
  1169.       Close (fd);
  1170.     }
  1171.   ISZERO = 1;
  1172.   ZeroRPT ();
  1173.   InitializeStats ();
  1174.   UpdateDisplay (0, 0, 1, 0);
  1175.   Sdepth = 0;
  1176.   hint = 0;
  1177. }
  1178.  
  1179. void
  1180. SaveGame (void)
  1181. {
  1182.   FILE *fd;
  1183.   char fname[256];
  1184.   INTSIZE sq, i, c, f, t;
  1185.   char p;
  1186.  
  1187.   if (!(GetFileName(savefile)))   
  1188.    { 
  1189.     return;
  1190.    }
  1191.   (void)SetTaskPri((struct Task *)myproc,0);
  1192.   if (savefile[0])
  1193.     strcpy (fname, savefile);
  1194.   else
  1195.     {
  1196. /* Enter file name*/
  1197.       ShowMessage (CP[63]);
  1198. #ifndef AMIGA
  1199.       scanz ("%s", fname);
  1200. #endif
  1201.     }
  1202.  
  1203.   if (fname[0] == '\0')
  1204. /* chess.000 */
  1205.     strcpy (fname, CP[137]);
  1206.   Delay(25L);
  1207.   if ((fd = fopen (fname, "w")) != NULL)
  1208.     {
  1209.       char *b, *w;
  1210.  
  1211.       Delay(25L);
  1212.       b = w = CP[74];
  1213.       if (computer == black)
  1214.     b = CP[141];
  1215.       if (computer == white)
  1216.     w = CP[141];
  1217.       fprintf (fd, CP[37], b, w, Game50,epsquare);
  1218.       fprintf (fd, CP[42], castld[white] ? CP[214] : CP[215], castld[black] ? CP[214] : CP[215]);
  1219.       fprintf (fd, CP[111], TCflag, OperatorTime);
  1220.       fprintf (fd, CP[117],
  1221.            TimeControl.clock[white], TimeControl.moves[white],
  1222.            TimeControl.clock[black], TimeControl.moves[black]);
  1223.       for (i = 7; i > -1; i--)
  1224.     {
  1225.       fprintf (fd, "%1d ", i + 1);
  1226.       for (c = 0; c < 8; c++)
  1227.         {
  1228.           sq = i * 8 + c;
  1229.           switch (color[sq])
  1230.         {
  1231.         case black:
  1232.           p = pxx[board[sq]];
  1233.           break;
  1234.         case white:
  1235.           p = qxx[board[sq]];
  1236.           break;
  1237.         default:
  1238.           p = '.';
  1239.         }
  1240.           fprintf (fd, "%c", p);
  1241.         }
  1242.       for (f = i * 8; f < i * 8 + 8; f++)
  1243.         fprintf (fd, " %d", Mvboard[f]);
  1244.       fprintf (fd, "\n");
  1245.     }
  1246.       fprintf (fd, "  %s\n", cxx);
  1247.       fprintf (fd, CP[126]);
  1248.       for (i = 1; i <= GameCnt; i++)
  1249.     {
  1250.       struct GameRec *g = &GameList[i];
  1251.  
  1252.       f = g->gmove >> 8;
  1253.       t = (g->gmove & 0xFF);
  1254.       algbr (f, t, g->flags);
  1255.       fprintf (fd, "%s %5d %5d %7ld %5d %5d  %#08lx %#08lx %d %c   %s\n",
  1256.            mvstr[0], g->score, g->depth,
  1257.            g->nodes, g->time, g->flags, g->hashkey, g->hashbd,g->epssq,
  1258.        pxx[g->piece], ((g->color == 2) ? "     " : ColorStr[g->color]));
  1259.     }
  1260.       fclose (fd);
  1261. /* Game saved */
  1262.       ShowMessage (CP[70]);
  1263.     }
  1264.   else
  1265.     /*ShowMessage ("Could not open file");*/
  1266.     ShowMessage (CP[48]);
  1267.   (void)SetTaskPri((struct Task *)myproc,procpri);
  1268. }
  1269.  
  1270. void
  1271. ListGame (getstr)
  1272. int getstr;
  1273. {
  1274.   FILE *fd;
  1275.   INTSIZE i, f, t;
  1276.   long when;
  1277.   char fname[256], dbuf[256];
  1278.  
  1279.   if (listfile[0])
  1280.     strcpy (fname, listfile);
  1281.   else
  1282.     {
  1283. #ifdef MSDOS
  1284.       sprintf (fname, "chess.lst");
  1285. #else
  1286.       if (!getstr)
  1287.        {
  1288.         time (&when);
  1289.         strncpy (dbuf, ctime (&when), 20);
  1290.         dbuf[7] = '\0';
  1291.         dbuf[10] = '\0';
  1292.         dbuf[13] = '\0';
  1293.         dbuf[16] = '\0';
  1294.         dbuf[19] = '\0';
  1295. /* use format "CLp16.Jan01-020304B" when patchlevel is 16,
  1296.    date is Jan 1
  1297.    time is 02:03:04
  1298.    program played black */
  1299.         sprintf (fname, "t:UC%s.%s%s-%s%s%s%c", patchlevel, dbuf + 4, dbuf + 8, dbuf + 11, dbuf + 14, dbuf + 17, ColorStr[computer][0]);
  1300.         /* replace space padding with 0 */
  1301.         for (i = 0; fname[i] != '\0'; i++)
  1302.         if (fname[i] == ' ')
  1303.         fname[i] = '0';
  1304.        }
  1305.       else
  1306.        {
  1307.         if (!GetFileName(fname))
  1308.          {
  1309.           return;
  1310.          }
  1311.        }
  1312. #endif /* MSDOS */
  1313.     }
  1314.   Delay(5L);
  1315.   (void)SetTaskPri((struct Task *)myproc,0);
  1316.   fd = fopen (fname, "w");
  1317.   Delay(5L);
  1318.   if (!fd)
  1319.     {
  1320.      (void)SetTaskPri((struct Task *)myproc,procpri);
  1321.      return;
  1322.     }
  1323.   /*fprintf (fd, "gnuchess game %d\n", u);*/
  1324.   fprintf (fd, "%s\n", VERSTRING);
  1325.   fprintf (fd, CP[10]);
  1326.   fprintf (fd, CP[11]);
  1327.   for (i = 1; i <= GameCnt; i++)
  1328.     {
  1329.       f = GameList[i].gmove >> 8;
  1330.       t = (GameList[i].gmove & 0xFF);
  1331.       algbr (f, t, GameList[i].flags);
  1332.       if(GameList[i].flags & book)
  1333.           fprintf (fd, "%5s  %5d    Book%7ld %5d", mvstr[0],
  1334.            GameList[i].score, 
  1335.            GameList[i].nodes, GameList[i].time);
  1336.       else
  1337.           fprintf (fd, "%5s  %5d     %2d %7ld %5d", mvstr[0],
  1338.            GameList[i].score, GameList[i].depth,
  1339.            GameList[i].nodes, GameList[i].time);
  1340.       if ((i % 2) == 0)
  1341.     {
  1342.       fprintf (fd, "\n");
  1343. #ifdef DEBUG40
  1344.       if (computer == black)
  1345.         fprintf (fd, " %d %d %d %d %d %d %d\n",
  1346.              GameList[i].d1,
  1347.              GameList[i].d2,
  1348.              GameList[i].d3,
  1349.              GameList[i].d4,
  1350.              GameList[i].d5,
  1351.              GameList[i].d6,
  1352.              GameList[i].d7);
  1353.       else
  1354.         fprintf (fd, " %d %d %d %d %d %d %d\n",
  1355.              GameList[i - 1].d1,
  1356.              GameList[i - 1].d2,
  1357.              GameList[i - 1].d3,
  1358.              GameList[i - 1].d4,
  1359.              GameList[i - 1].d5,
  1360.              GameList[i - 1].d6,
  1361.              GameList[i - 1].d7);
  1362. #endif
  1363.     }
  1364.       else
  1365.     fprintf (fd, "         ");
  1366.     }
  1367.   fprintf (fd, "\n\n");
  1368.   if (GameList[GameCnt].flags & draw)
  1369.     {
  1370.       fprintf (fd, CP[54], DRAW);
  1371.     }
  1372.   else if (GameList[GameCnt].score == -9999)
  1373.     {
  1374.       fprintf (fd, "%s\n", ColorStr[player ]);
  1375.     }
  1376.   else if (GameList[GameCnt].score == 9998)
  1377.     {
  1378.       fprintf (fd, "%s\n", ColorStr[player ^ 1]);
  1379.     }
  1380.   fclose (fd);
  1381.   (void)SetTaskPri((struct Task *)myproc,procpri);
  1382. }
  1383.  
  1384. void
  1385. Undo (void)
  1386.  
  1387. /*
  1388.  * Undo the most recent half-move.
  1389.  */
  1390.  
  1391. {
  1392.   INTSIZE f, t;
  1393.   f = GameList[GameCnt].gmove >> 8;
  1394.   t = GameList[GameCnt].gmove & 0xFF;
  1395.   if (board[t] == king && distance (t, f) > 1)
  1396.     (void) castle (GameList[GameCnt].color, f, t, 2);
  1397.   else
  1398.     {
  1399.       /* Check for promotion: */
  1400.       if (GameList[GameCnt].flags & promote)
  1401.     {
  1402.       board[t] = pawn;
  1403.     }
  1404.       board[f] = board[t];
  1405.       color[f] = color[t];
  1406.       board[t] = GameList[GameCnt].piece;
  1407.       color[t] = GameList[GameCnt].color;
  1408.       if (color[t] != neutral)
  1409.     Mvboard[t]--;
  1410.       Mvboard[f]--;
  1411.     }
  1412.   if (GameList[GameCnt].flags & epmask)
  1413.     EnPassant (otherside[color[f]], f, t, 2);
  1414.   else
  1415.     InitializeStats ();
  1416.   epsquare = GameList[GameCnt].epssq;
  1417.   if (TCflag && (TCmoves>1))
  1418.     ++TimeControl.moves[color[f]];
  1419.   hashkey = GameList[GameCnt].hashkey;
  1420.   hashbd = GameList[GameCnt].hashbd;
  1421.   GameCnt--;
  1422.   computer = computer ^ 1;
  1423.   opponent = opponent ^ 1;
  1424.   Mate = flag.mate = false;
  1425.   Sdepth = 0;
  1426.   player = player ^ 1;
  1427.   ShowSidetoMove ();
  1428.   UpdateDisplay (0, 0, 1, 0);
  1429.  
  1430.   InitializeStats();
  1431.  
  1432. #if defined NULLMOVE || defined DEEPNULL
  1433.   no_null=0;
  1434.   null = 0;         /* Null-move already made or not */
  1435.   PVari = 0;        /* Is this the PV */
  1436. #endif
  1437.   dither = 0;
  1438.   PawnStorm = start_stage = 0;
  1439.   thrashing_tt = 0; /* must we recycle slots at random. TomV */
  1440.   ClearMem(QueenCheck,MAXDEPTH*sizeof(short));
  1441.   ClearMem(PrVar,MAXDEPTH*sizeof(short));
  1442.   ClearMem(Threat,MAXDEPTH*sizeof(short));
  1443.   ClearMem(ThreatSave,MAXDEPTH*sizeof(short));
  1444.   ClearMem(Pscore,MAXDEPTH*sizeof(short));
  1445.   ClearMem(Tscore,MAXDEPTH*sizeof(short));
  1446.   ClearMem(ChkFlag,MAXDEPTH*sizeof(short));
  1447.   ClearMem(CptrFlag,MAXDEPTH*sizeof(short));
  1448.   ClearMem(PawnThreat,MAXDEPTH*sizeof(short));
  1449.  
  1450.  
  1451.   //ZeroRPT();
  1452.   ZeroTTable(0);
  1453. #ifndef AMIGA
  1454.    memset ((signed char *) etab, 0, sizeof (etab));
  1455. #else
  1456.    ClearMem(etab,sizeof(etab));
  1457. #endif
  1458. #ifdef HISTORY
  1459.  ClearMem(history,sizeof(history));
  1460. #endif
  1461.  MoveMem128(board,amigaboard);
  1462.  MoveMem128(color,amigacolor);
  1463. /*  if (flag.regularstart)
  1464.     Book = BOOKFAIL;*/
  1465. }
  1466.  
  1467. void
  1468.  TestSpeed (void (*f) ( INTSIZE int side, INTSIZE int ply), unsigned j)
  1469. {
  1470.   char astr[256];
  1471.   INTSIZE i;
  1472.   long cnt, rate, t1, t2;
  1473.  
  1474.   t1 = time (0);
  1475.   Forbid();
  1476.   for (i = 0; i < j; i++)
  1477.     {
  1478.       f (opponent, 2);
  1479.     }
  1480.   Permit();
  1481.   t2 = time (0);
  1482.   cnt = j * (TrPnt[3] - TrPnt[2]);
  1483.   if (t2 - t1)
  1484.     et = (t2 - t1) * 100;
  1485.   else
  1486.     et = 1;
  1487.   rate = (et) ? (cnt / et) : 0;
  1488.   /*printz ("Nodes= %ld Nodes/sec= %ld\n", cnt, rate);*/
  1489. #ifdef NONDSP
  1490. #ifdef AMIGA
  1491. if (!func_num)
  1492.  sprintf(astr,"Mlst=%dN/s",rate*100);
  1493. else if (func_num == 1)
  1494.  sprintf(astr,"Clst=%dN/s",rate*100);
  1495. ShowMessage(astr);
  1496. #else
  1497.   printz (CP[91], cnt, rate*100);
  1498. #endif
  1499. #ifdef DEBUG9
  1500.   for (j = TrPnt[2]; j < TrPnt[3]; j++)
  1501.     {
  1502.       struct leaf *node = &Tree[j];
  1503.       algbr (node->f, node->t, node->flags);
  1504.       printf ("%s %s %s %s %d %x\n", mvstr[0], mvstr[1], mvstr[2], mvstr[3],node->score,node->flags);
  1505.     }
  1506. #endif
  1507. #else
  1508.   ShowNodeCnt (cnt);
  1509. #endif
  1510. }
  1511.  
  1512. void
  1513.  TestPSpeed (INTSIZE int (*f) (INTSIZE int side), unsigned j)
  1514. {
  1515.   char astr[256];
  1516.   INTSIZE i;
  1517.   long cnt, rate, t1, t2;
  1518.  
  1519.   t1 = time (0);
  1520.   Forbid();
  1521.   for (i = 0; i < j; i++)
  1522.     {
  1523.       (void) f (opponent);
  1524.     }
  1525.   Permit();
  1526.   t2 = time (0);
  1527.   cnt = j;
  1528.   if (t2 - t1)
  1529.     et = (t2 - t1) * 100;
  1530.   else
  1531.     et = 1;
  1532.   rate = (et) ? (cnt / et) : 0;
  1533.   /*printz ("Nodes= %ld Nodes/sec= %ld\n", cnt, rate);*/
  1534. #ifdef NONDSP
  1535. #ifdef AMIGA
  1536. sprintf(astr,"Eval=%ldN/s",rate*100);
  1537. ShowMessage(astr);
  1538. #else
  1539.   printz (CP[91], cnt, rate*100);
  1540. #endif
  1541. #else
  1542.   ShowNodeCnt (cnt);
  1543. #endif
  1544. }
  1545.  
  1546.  
  1547. void
  1548. SetMachineTime (char *s)
  1549. {
  1550.   char *time;
  1551.   int m, t;
  1552.   time = &s[strlen (CP[197])];
  1553.   m = strtol (time, &time, 10);
  1554.   t = strtol (time, &time, 10);
  1555.   if (t)
  1556.     TimeControl.clock[computer] = t;
  1557.   if (m)
  1558.     TimeControl.moves[computer] = m;
  1559. #ifdef XBOARD
  1560.   printz (CP[222], m, t);
  1561. #endif
  1562. }
  1563.  
  1564.  
  1565. void
  1566. InputCommand (cstring)
  1567.  
  1568. char *cstring;
  1569.  
  1570. /*
  1571.  * Process the users command. If easy mode is OFF (the computer is thinking
  1572.  * on opponents time) and the program is out of book, then make the 'hint'
  1573.  * move on the board and call SelectMove() to find a response. The user
  1574.  * terminates the search by entering ^C (quit siqnal) before entering a
  1575.  * command. If the opponent does not make the hint move, then set Sdepth to
  1576.  * zero.
  1577.  */
  1578.  
  1579. {
  1580.   int tmpPawnStorm;
  1581.   int need_to_zero;
  1582.   char tstr[40];
  1583.   int i = 0;
  1584.   INTSIZE have_shown_prompt = false;
  1585.   INTSIZE ok, tmp;
  1586.   unsigned INTSIZE mv;
  1587.   char s[80];
  1588.   char *sx;
  1589.  
  1590.   sx = OpEntryStr;
  1591.   tmpPawnStorm = PawnStorm;
  1592. #if defined CHESSTOOL
  1593.   INTSIZE normal = false;
  1594.  
  1595. #endif
  1596.  
  1597.   ok = flag.quit = false;
  1598.   MoveMem128(board,amigaboard);
  1599.   MoveMem128(color,amigacolor);
  1600.   player = opponent;
  1601.   ft = 0;
  1602.   thinkahead = 0;
  1603. #ifdef CACHE
  1604. //  if(TTadd > ttblsize) // want to zero out ttable each time
  1605.    ZeroTTable(1);
  1606. #endif
  1607.   if (hint > 0 && !flag.easy && !flag.force)
  1608.     if ((board[hint >> 8] != pawn) || ((row (hint & 0x3f) != 0) && (row (hint & 0x3f) != 7)))
  1609.       {
  1610.         s[0] = sx[0] = '\0';
  1611.         thinkahead = 1;
  1612.         ft = time0;
  1613.     algbr ((INTSIZE) hint >> 8, (INTSIZE) hint & 0x3F, false);
  1614.     strcpy (s, mvstr[0]);
  1615.     tmp = epsquare;
  1616.         verifyquiet = 1;
  1617.     if (VerifyMove (s, 1, &mv))
  1618.       {
  1619.         Sdepth = 0;
  1620. #ifdef QUIETBACKGROUND
  1621. #ifdef NONDSP
  1622.         PromptForMove ();
  1623. #else
  1624.         ShowSidetoMove ();
  1625.         ShowPrompt ();
  1626. #endif
  1627.         have_shown_prompt = true;
  1628. #endif /* QUIETBACKGROUND */
  1629.             backsrchaborted = 0;
  1630.             if (!GetEntryDone)
  1631.              {
  1632.               Global_Message.myData = 1L;
  1633.               Forbid();
  1634.               PutMsg(InThreadPort,(struct Message *)&Global_Message);
  1635.               Permit();
  1636.               GetEntryDone = 1;
  1637.              }
  1638.         SelectMove (computer, 2);
  1639. #ifdef OLD_LOOKAHEAD
  1640.         VerifyMove (s, 2, &mv);
  1641.         Sdepth = 0;
  1642. #else // faster lookahead on predict
  1643.         VerifyMove (s, 2, &mv);
  1644.         if ((Sdepth > 0)&&(backsrchaborted))
  1645.               Sdepth--;
  1646. #endif
  1647.       }
  1648.          verifyquiet = 0;
  1649.     /*ft = (time ((long *) 0) - time0) * 100;*/
  1650.     epsquare = tmp;
  1651.     time0 = ft;
  1652.       }
  1653.   while (!(ok || flag.quit))
  1654.     {
  1655.       need_to_zero = 0;
  1656. #if defined CHESSTOOL
  1657.       normal = false;
  1658. #endif
  1659.       player = opponent;
  1660. #ifdef QUIETBACKGROUND
  1661.       if (!have_shown_prompt)
  1662.     {
  1663. #endif /* QUIETBACKGROUND */
  1664. #ifdef NONDSP
  1665.       PromptForMove ();
  1666. #else
  1667.       ShowSidetoMove ();
  1668.       ShowPrompt ();
  1669. #endif
  1670. #ifdef QUIETBACKGROUND
  1671.     }
  1672.       have_shown_prompt = false;
  1673. #endif /* QUIETBACKGROUND */
  1674. #ifdef NONDSP
  1675.       if (!GetEntryDone)
  1676.        s[0] = sx[0] = '\0';
  1677. #ifndef AMIGA
  1678.       while (!sx[0])
  1679.     i = (int) gets (sx);
  1680. #else
  1681.        thinking2 = 0;
  1682.        i = 1;
  1683.        thinkahead = 0;
  1684.        if (!GetEntryDone)
  1685.         {
  1686.          Global_Message.myData = 1L;
  1687.          Forbid();
  1688.          PutMsg(InThreadPort,(struct Message *)&Global_Message);
  1689.          Permit();
  1690.         }
  1691.        GetEntryDone = 0;
  1692.        if (Wait(MYREPLY) & MYREPLY)
  1693.         { // string is waiting for me!
  1694.            //GetOperatorEntry(); // TMP DEBUG STATEMENT
  1695.         }
  1696.        else // funny wake up, should not happen!
  1697.         {
  1698.          strcpy(sx,"quit");
  1699.         }
  1700. #endif
  1701. #else
  1702.      /* fflush (stdout);
  1703.       i = (int) getstr (sx);*/
  1704. #endif
  1705.       sscanf (sx, "%s", s);
  1706.       if (i == EOF)
  1707.     ExitChess ();
  1708.       if (s[0] == '\0')
  1709.     continue;
  1710.       if (strcmp (s, CP[131]) == 0)    /*bd*/
  1711.     {
  1712. #if defined CHESSTOOL || defined XBOARD
  1713.       chesstool = 0;
  1714. #endif /* CHESSTOOL */
  1715.       ClrScreen ();
  1716.       UpdateDisplay (0, 0, 1, 0);
  1717. #if defined CHESSTOOL || defined XBOARD
  1718.       chesstool = 1;
  1719. #endif /* CHESSTOOL */
  1720.     }
  1721.       else if (strcmp (s, CP[129]) == 0) /* noop */ ;    /*alg*/
  1722.       else if ((strcmp (s, CP[180]) == 0) || (strcmp (s, CP[216]) == 0))    /* quit exit*/
  1723.     flag.quit = true;
  1724.       else if (strcmp (s, CP[178]) == 0)    /*post*/
  1725.     {
  1726.      /* flag.post = !flag.post;*/
  1727.     }
  1728.       else if ((strcmp (s, CP[191]) == 0) || (strcmp (s, CP[154]) == 0))    /*set edit*/
  1729.     EditBoard ();
  1730. #ifdef NONDSP
  1731.       else if (strcmp (s, CP[190]) == 0)    /*setup*/
  1732.     SetupBoard ();
  1733. #endif
  1734.       else if (strcmp (s, CP[156]) == 0)    /*first*/
  1735.     {
  1736. #if defined CHESSTOOL
  1737.       computer = white;
  1738.       opponent = black;
  1739.       flag.force = false;
  1740.       Sdepth = 0;
  1741. #endif /* CHESSTOOL */
  1742.       ok = true;
  1743.     }
  1744.       else if (strcmp (s, CP[162]) == 0)    /*go*/
  1745.     {
  1746.       ok = true;
  1747.       flag.force = false;
  1748.       if (computer == white)
  1749.         {
  1750.           computer = black;
  1751.           opponent = white;
  1752.         }
  1753.       else
  1754.         {
  1755.           computer = white;
  1756.           opponent = black;
  1757.         }
  1758.     }
  1759.       else if (strcmp (s, CP[166]) == 0)    /*help*/
  1760.     help ();
  1761.       else if (strcmp (s, CP[221]) == 0)    /*material*/
  1762.     flag.material = !flag.material;
  1763.       else if (strcmp (s, CP[157]) == 0)    /*force*/
  1764.     {flag.force = !flag.force; flag.bothsides = false;}
  1765.       else if (strcmp (s, CP[134]) == 0)    /*book*/
  1766.     Book = Book ? 0 : BOOKFAIL;
  1767.       else if (strcmp (s, CP[172]) == 0)    /*new*/
  1768.     {
  1769.       NewGame ();
  1770.       UpdateDisplay (0, 0, 1, 0);
  1771.     }
  1772.       //else if (strcmp (s, CP[171]) == 0)    /*list*/
  1773.     //ListGame (0xff);
  1774.       else if (strcmp (s, CP[169]) == 0 || strcmp (s, CP[217]) == 0)    /*level clock*/
  1775.        {
  1776.         GetTimeString(tstr);
  1777.     SelectLevel (tstr);
  1778.        }
  1779.       else if (strcmp (s, CP[165]) == 0)    /*hash*/
  1780.     flag.hash = !flag.hash;
  1781.       else if (strcmp (s, CP[132]) == 0)    /*beep*/
  1782.     flag.beep = !flag.beep;
  1783.       else if (strcmp (s, CP[197]) == 0)    /*time*/
  1784.     {
  1785.       SetMachineTime (sx);
  1786.     }
  1787.       else if (strcmp (s, CP[33]) == 0)    /*Awindow*/
  1788.     ChangeAlphaWindow ();
  1789.       else if (strcmp (s, CP[39]) == 0)    /*Bwindow*/
  1790.     ChangeBetaWindow ();
  1791.       else if (strcmp (s, CP[183]) == 0)    /*rcptr*/
  1792.     flag.rcptr = !flag.rcptr;
  1793.       else if (stricmp(s,"calc") == 0)
  1794.        {
  1795.         calc_pgm_rating();
  1796.         OpEntryStr[0] = 0;
  1797.         s[0] = 0;
  1798.        }
  1799.       else if (stricmp(s,"advan") == 0)
  1800.        {
  1801.         DoAdvanced();
  1802.         OpEntryStr[0] = 0;
  1803.         s[0] = 0;
  1804.        }
  1805.       else if (stricmp(s,"interm") == 0)
  1806.        {
  1807.         DoIntermediate();
  1808.         OpEntryStr[0] = 0;
  1809.         s[0] = 0;
  1810.        }
  1811.       else if (stricmp(s,"easy") == 0)
  1812.        {
  1813.         DoEasy();
  1814.         OpEntryStr[0] = 0;
  1815.         s[0] = 0;
  1816.        }
  1817.       else if (strcmp (s, CP[168]) == 0)    /*hint*/
  1818.        {
  1819.     GiveHint ();
  1820.        }
  1821.       else if (strcmp (s, CP[135]) == 0)    /*both*/
  1822.     {
  1823.       flag.bothsides = !flag.bothsides;
  1824.           if (flag.bothsides)
  1825.            {
  1826.             (void)SetTaskPri((struct Task *)myproc,0);
  1827.             thinkahead = 1;
  1828.            }
  1829.           flag.force = false;
  1830.       Sdepth = 0;
  1831.       ElapsedTime (1);
  1832.       SelectMove (opponent, 1);
  1833.       ok = true;
  1834.     }
  1835.       else if (strcmp (s, CP[185]) == 0)    /*reverse*/
  1836.     {
  1837. #ifndef AMIGA
  1838.       flag.reverse = !flag.reverse;
  1839.       ClrScreen ();
  1840.       UpdateDisplay (0, 0, 1, 0);
  1841. #endif
  1842.     }
  1843.       else if (strcmp (s, CP[195]) == 0)    /*switch*/
  1844.     {
  1845.       computer = computer ^ 1;
  1846.       opponent = opponent ^ 1;
  1847.       xwndw = (computer == white) ? WXWNDW : BXWNDW;
  1848.       flag.force = false;
  1849.       Sdepth = 0;
  1850.       if ((!GameCnt) && (Book) && (flag.regularstart))
  1851.        GetOpenings(computer);
  1852.           else
  1853.            Book = 0;
  1854.       ok = true;
  1855.     }
  1856.       else if (strcmp (s, CP[203]) == 0)    /*white*/
  1857.     {
  1858.       computer = black;
  1859.       opponent = white;
  1860.       xwndw = WXWNDW;
  1861.       flag.force = false;
  1862.       Sdepth = 0;
  1863.  
  1864.       /*
  1865.            * ok = true; don't automatically start with white command
  1866.            */
  1867.     }
  1868.       else if (strcmp (s, CP[133]) == 0)    /*black*/
  1869.     {
  1870.       computer = white;
  1871.       opponent = black;
  1872.       xwndw = BXWNDW;
  1873.       flag.force = false;
  1874.       Sdepth = 0;
  1875.  
  1876.       /*
  1877.            * ok = true; don't automatically start with black command
  1878.            */
  1879.     }
  1880.       else if (strcmp (s, CP[201]) == 0 && GameCnt > 0)    /*undo*/
  1881.     {
  1882. #ifndef AMIGA
  1883.       Undo ();
  1884. #endif
  1885.     }
  1886.       else if (strcmp (s, CP[184]) == 0 && GameCnt > 1)    /*remove*/
  1887.     {
  1888. #ifndef AMIGA
  1889.       Undo ();
  1890.       Undo ();
  1891. #endif
  1892.     }
  1893.       //else if (strcmp (s, CP[160]) == 0)    /*get*/
  1894.     //GetGame ();
  1895.       //else if (strcmp (s, CP[207]) == 0)    /*xget*/
  1896.     //GetXGame ();
  1897.       //else if (strcmp (s, CP[189]) == 0)    /*save*/
  1898.     //SaveGame ();
  1899.       else if (strcmp (s, CP[151]) == 0)    /*depth*/
  1900.     ChangeSearchDepth ();
  1901. #ifdef DEBUG
  1902.       else if (strcmp (s, CP[147]) == 0)    /*debuglevel*/
  1903.     ChangeDbLev ();
  1904. #endif /* DEBUG */
  1905.       else if (strcmp (s, CP[164]) == 0)    /*hashdepth*/
  1906.     ChangeHashDepth ();
  1907.       else if (strcmp (s, CP[182]) == 0)    /*random*/
  1908.     dither = DITHER;
  1909.       else if (strcmp (s, CP[152]) == 0)    /*easy*/
  1910.        {
  1911.     /*flag.easy = !flag.easy;*/
  1912.     flag.easy = flag.easy; /* mod this for menu toggle on amiga */
  1913.        }
  1914.       else if (strcmp (s, CP[143]) == 0)    /*contempt*/
  1915.     SetContempt ();
  1916.       else if (strcmp (s, CP[209]) == 0)    /*xwndw*/
  1917.     ChangeXwindow ();
  1918.       else if (strcmp (s, CP[186]) == 0)    /*rv*/
  1919.     {
  1920.       flag.rv = !flag.rv;
  1921.       UpdateDisplay (0, 0, 1, 0);
  1922.     }
  1923.       else if (strcmp (s, CP[145]) == 0)    /*coords*/
  1924.     {
  1925.       flag.coords = !flag.coords;
  1926.       UpdateDisplay (0, 0, 1, 0);
  1927.     }
  1928.       else if (strcmp (s, CP[193]) == 0)    /*stras*/
  1929.     {
  1930.       flag.stars = !flag.stars;
  1931.       UpdateDisplay (0, 0, 1, 0);
  1932.     }
  1933.       else if (strcmp (s, CP[196]) == 0)    /*test*/
  1934.     {
  1935. /*      ShowMessage (CP[108]);/*test movelist*/
  1936.           ShowMessage ("Testing..");
  1937.           func_num = 0;
  1938.       TestSpeed (MoveList, 20000);
  1939. /*      ShowMessage (CP[107]);/*test capturelist*/
  1940.           func_num++;
  1941.       TestSpeed (CaptureList, 30000);
  1942. /*      ShowMessage (CP[85]);/*test score position*/
  1943.           func_num++;
  1944.       TestPSpeed (ScorePosition, 15000);
  1945.     }
  1946.       //else if (strcmp (s, CP[179]) == 0)    /*p*/
  1947.     //ShowPostnValues ();
  1948. #ifdef DEBUGG
  1949.       else if (strcmp (s, CP[148]) == 0)    /*debug*/
  1950.     DoDebug ();
  1951.     else if (strcmp (s, "Mwpawn") == 0)        /*debug*/
  1952.         DoTable (Mwpawn);
  1953.     else if (strcmp (s, "Mbpawn") == 0)        /*debug*/
  1954.         DoTable (Mbpawn);
  1955.     else if (strcmp (s, "Mwknight") == 0)        /*debug*/
  1956.         DoTable (Mknight[white]);
  1957.     else if (strcmp (s, "Mbknight") == 0)        /*debug*/
  1958.         DoTable (Mknight[black]);
  1959.     else if (strcmp (s, "Mwbishop") == 0)        /*debug*/
  1960.         DoTable (Mbishop[white]);
  1961.     else if (strcmp (s, "Mbbishop") == 0)        /*debug*/
  1962.         DoTable (Mbishop[black]);
  1963. #endif
  1964.       else
  1965.     { /* this is where we move the humans pieces */
  1966. #if defined CHESSTOOL
  1967.       normal = (ok = VerifyMove (s, 0, &mv));
  1968. #else
  1969.       ok = VerifyMove (s, 0, &mv);
  1970. #endif
  1971. #ifdef OLDVERSION1_01
  1972.       if ((ok && mv != hint))
  1973.         {
  1974.           Sdepth = 0;
  1975.           ft = 0;
  1976.         }
  1977.       else
  1978.         Sdepth = 0;
  1979. #else
  1980. #ifndef OLD_LOOKAHEAD
  1981.           if ((ok)&&((mv != hint)||(flag.easy)||(Sdepth2<3)||(GameCnt <= 2)))
  1982.            {
  1983. #ifndef CLEARHISTBETWEENMOVES
  1984.             if (!flag.easy) // if  thinkahead was wrong clear hist
  1985.              ClearMem(history,sizeof (history));
  1986. #endif
  1987.             Sdepth = 0;
  1988.             need_to_zero = 1;
  1989.            }
  1990.          else // TMP DEBUG UNTIL I CAN GET SOMETHING BETTER
  1991.           {
  1992.             Sdepth = 0;
  1993.             need_to_zero = 1;
  1994.           }
  1995. #endif
  1996.           if (ok)
  1997.            {
  1998.         if ((!flag.easy)&&(mv == hint)&&(Sdepth2>2)&&(GameCnt > 2))
  1999.              {
  2000.               ThinkAheadDepth = Sdepth2;
  2001.               //if (ThinkInARow > 4) /* if it got to 4, we would have skipped one */
  2002.                ThinkInARow = 0;
  2003.               ThinkAheadWorked = 1;
  2004.              }
  2005.             else
  2006.              {
  2007. #ifndef CLEARHISTBETWEENMOVES
  2008.               if (!flag.easy) // if thinkahead is wrong clear hist
  2009.                ClearMem(history,sizeof (history));
  2010. #endif
  2011.               ThinkInARow = 0;
  2012.               ThinkAheadDepth = 0;
  2013.               ThinkAheadWorked = 0;
  2014.              }
  2015.            } // ok
  2016. #endif
  2017.           if ((!ok))
  2018.            {
  2019.             IllegalMove = 1;
  2020.            }
  2021.           if ((ok)&&(MouseDropped))
  2022.            {
  2023.                 DoLegalMove(s);
  2024.                 MouseDropped = 0;
  2025.            }
  2026.           //ClearMem(etab,sizeof(etab)); // I find it buggy to keep around!
  2027.           if (need_to_zero)
  2028.            {
  2029.             if (!flag.easy)
  2030.              PawnStorm = tmpPawnStorm;
  2031.             need_to_zero = 0;
  2032. //            if (!flag.easy)
  2033. //#ifndef AGING
  2034. //             ZeroTTable(0);
  2035. //#else
  2036. //             ZeroTTable(0);
  2037. //#endif
  2038.            }
  2039.           if (!ok)
  2040.            MouseDropped = 0;
  2041.     }
  2042.     }
  2043.  
  2044.   ElapsedTime (1);
  2045.   if (flag.force)
  2046.     {
  2047.       computer = opponent;
  2048.       opponent = computer ^ 1;
  2049.     }
  2050. }
  2051.  
  2052.  
  2053. void
  2054. ElapsedTime (INTSIZE int iop)
  2055.  
  2056.  
  2057. /*
  2058.  * Determine the time that has passed since the search was started. If the
  2059.  * elapsed time exceeds the target (ResponseTime+ExtraTime) then set timeout
  2060.  * to true which will terminate the search. iop = 0 calculate et bump ETnodes
  2061.  * iop = 1 calculate et set timeout if time exceeded, calculate et
  2062.  */
  2063.  
  2064. {
  2065. #ifndef MSDOS
  2066.   extern int errno;
  2067. #ifdef AMIGA
  2068.    //struct IntuiMessage *localmessage;
  2069.    //long __aligned class,code;
  2070. #endif
  2071. #ifndef AMIGA
  2072. #ifdef FIONREAD
  2073.   if (i = ioctl ((int) 0, FIONREAD, &nchar))
  2074.     {
  2075.       perror ("FIONREAD");
  2076.       fprintf (stderr,
  2077.         "You probably have a non-ANSI <ioctl.h>; see README. %d %d %x\n",
  2078.     i, errno, FIONREAD);
  2079.       exit (1);
  2080.     }
  2081.  
  2082.   if (nchar)
  2083.     {
  2084.       if (!flag.timeout)
  2085.     flag.back = true;
  2086.       flag.bothsides = false;
  2087.     }
  2088. #endif /*FIONREAD*/
  2089. #endif
  2090. #ifdef AMIGA /* check if I need to interrupt thinking */
  2091. #ifndef OLDWAY
  2092.   if (OpEntryRecvd)
  2093.    {
  2094.     OpEntryRecvd = 0;
  2095.     if ((thinkahead)&&(!flag.bothsides))
  2096.      {
  2097.           (void)SetTaskPri((struct Task *)myproc,procpri);
  2098.           if (!TCflag)
  2099.            backsrchaborted = 1;
  2100.           if (!flag.timeout)
  2101.            {
  2102.             flag.back = true;
  2103.            }
  2104.           flag.bothsides = false;
  2105.      }
  2106.     else if (thinking2)
  2107.      {
  2108.       if (OpEntryRecvd == 2)
  2109.        { // move now!
  2110.              if (!flag.timeout)
  2111.               {
  2112.                flag.back = true;
  2113.               flag.musttimeout = true;
  2114.               }
  2115.              flag.bothsides = false;
  2116.        }
  2117.      }
  2118.    }
  2119. #else
  2120.   if (thinkahead)
  2121.   {
  2122.   while ( (localmessage = (struct IntuiMessage *)
  2123.     GetMsg(wG->UserPort) )) /* got a message at window port */
  2124.    {
  2125.         if (localmessage->Class == RAWKEY)
  2126.          {
  2127.           if (localmessage->Code < 56)
  2128.            code = cookedchar[localmessage->Code];
  2129.           else
  2130.            code = 0;
  2131.          }
  2132.         else
  2133.          {
  2134.           code = 'A';
  2135.          }
  2136.         if (isalpha(code))
  2137.          {
  2138.           (void)SetTaskPri((struct Task *)myproc,procpri);
  2139.           if (!TCflag)
  2140.            backsrchaborted = 1;
  2141.           if (!flag.timeout)
  2142.            {
  2143.             flag.back = true;
  2144.            }
  2145.           flag.bothsides = false;
  2146.       globalmessage_valid = 0xffff;
  2147.           globalmessage = *localmessage;
  2148.          }
  2149.     ReplyMsg((struct Message *)localmessage);
  2150.    }
  2151.   }
  2152.   else if (thinking2) /* check for move now menu item */
  2153.   {
  2154.   while ( (localmessage = (struct IntuiMessage *)
  2155.     GetMsg(wG->UserPort) )) /* got a message at window port */
  2156.    {
  2157.     class = localmessage->Class;
  2158.         code = localmessage->Code;
  2159.     ReplyMsg((struct Message *)localmessage);
  2160.         if ((class == MENUPICK))
  2161.           {
  2162.         if (ItemAddress(&Menu1,code) == &MenuItem6)
  2163.             {
  2164.              if (!flag.timeout)
  2165.               {
  2166.                flag.back = true;
  2167.               flag.musttimeout = true;
  2168.               }
  2169.              flag.bothsides = false;
  2170.             }
  2171.           }
  2172.    }
  2173.   }
  2174. #endif // oldway
  2175. #endif
  2176. #else
  2177.   if (kbhit ())
  2178.     {
  2179.       if (!flag.timeout)
  2180.     flag.back = true;
  2181.       flag.bothsides = false;
  2182.     }
  2183. #endif /* MSDOS */
  2184.   et = (time ((long *) 0) - time0) * 100;
  2185.   ETnodes = NodeCnt + ZNODES;
  2186.   if (et < 0)
  2187.     et = 0;
  2188.   if (iop == 1)
  2189.     {
  2190.       if (et > ResponseTime + ExtraTime && Sdepth > MINDEPTH)
  2191.     flag.timeout = true;
  2192.       ETnodes = NodeCnt + ZNODES;
  2193.       time0 = time ((long *) 0);
  2194.     }
  2195. #ifdef AMIGA
  2196.     UpdateClocks ();
  2197. #endif
  2198. }
  2199.  
  2200.  
  2201. void
  2202. SetTimeControl (void)
  2203. {
  2204.  int tmp;
  2205.   if (TCflag)
  2206.     {
  2207.       TimeControl.moves[white] = TimeControl.moves[black] = TCmoves;
  2208.       TimeControl.clock[white] = 6000L * TCminutes + TCseconds * 100;
  2209.       TimeControl.clock[black] = 6000L * TCminutes + TCseconds * 100;
  2210.       SecsPerMove = tmp = (TCminutes*60+TCseconds)/TCmoves;
  2211.       if (tmp < 10)
  2212.        {
  2213.         GlobalTgtDepth = 2;
  2214.        }
  2215.       else if (tmp < 180)
  2216.        {
  2217.         GlobalTgtDepth = 3;
  2218.        }
  2219.       else
  2220.        GlobalTgtDepth = 4;
  2221.     }
  2222.   else
  2223.     {
  2224.       TimeControl.moves[white] = TimeControl.moves[black] = 0;
  2225.       TimeControl.clock[white] = TimeControl.clock[black] = 0;
  2226.     }
  2227.   flag.onemove = (TCmoves == 1);
  2228.   et = 0;
  2229.   ElapsedTime (1);
  2230. }
  2231.